package common.util
{
	
	import flash.net.LocalConnection;
	import flash.system.System;
	
	import mx.core.FlexGlobals;
	import mx.utils.URLUtil;

	public class SystemUtil	
	{
		public function SystemUtil()
		{
		}
		
		private static var WEB_URL:String;
		
		public static function getWebUrl():String{
			if(WEB_URL){
				return WEB_URL;
			}
			var REMOTE_FILE_URL:String = SystemUtil.getServerUrl();   
			var LOCAL_FILE_URL:String = "http://localhost/wqgps/"; 
			WEB_URL = REMOTE_FILE_URL.indexOf("file")!=-1?LOCAL_FILE_URL:REMOTE_FILE_URL;//自动识别当前部署环境
			return WEB_URL;
		}
		
		/**
		 * 获取服务器URL地址
		 */
		private static function getServerUrl():String{
			var url:String = FlexGlobals.topLevelApplication.url;
			var fullURL:String = URLUtil.getFullURL(url, url);
			var lastIndex:int = fullURL.lastIndexOf("/");
			var serverUrl:String = fullURL.substring(0,lastIndex).concat("/");
			return serverUrl;
		}
		
		
	  	public static function gc() : void  {
			try {
				new LocalConnection().connect( 'foo' );
				new LocalConnection().connect( 'foo' );
			} catch ( e : * ) {}
		}
		
		public static function get used() : Number {
			return System.totalMemory;
		}
	
		/**
		 * 是否为开发调试模式
		 */ 
		public static function isDebugModel():Boolean{
			var localFlag:Boolean = SystemUtil.getServerUrl().indexOf("file")!=-1?true:false;//自动识别当前部署环境
			return localFlag;
		}
	
	}
}